home *** CD-ROM | disk | FTP | other *** search
- PROCEDURE HotShot2;
- {
- Author: David Malmberg
-
- Strategy: Stay in one place. Find a foe. Take a shot.
- Keep improving aim and shooting until foe is lost from sights.
- Then move sights (scanning) to adjacent target area.
- If the Robot scans a complete circle (360 degrees) without
- finding a foe in shooting range, move to another spot on the
- field. (This will avoid "stand-offs" where opponents stay
- just out of range of one another.) RaiseShield when standing
- still and lower them when moving.
-
- When damage gets to 70 (or more) or fuel (if using fuel) gets
- below 200 adopt an "End-Game" strategy of moving to the lower
- left corner, lower shield, and continue to scan and shoot in
- the corner's 90 degree range.
-
- This Robot should be VERY effective against foes which
- are stopped or are moving slowly. It will be less effective
- against Robots traveling at high speeds.
-
- This Robot has been designed to utilize Fuel (if it is available)
- to power its Shield. However, it has not been designed to deal
- effectively with Obstructions.
- }
-
-
- VAR { HotShot2 "Global" variables }
-
- Angle, { Scanning angle }
- Last_Damage, { Robot's Last damage value }
- Range, { Range/Distance to foe }
- Sweep, { "Sweep count" -- when = 18, Robot has scanned 360 degrees }
- Delta : Integer; { Scanning arc }
-
-
- PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
- {
- Improve aim by doing a binary search of the target area.
- I.E., divide the target area in two equal pieces and redefine
- the target area to be the piece where the foe is found.
- If the foe is not found, expand the search area to the
- maximum arc of plus or minus 10 degrees.
- }
- BEGIN
- Arc := Arc DIV 2; { Divide search area in two. }
- IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
- THEN Ang := Ang-Arc { If foe found, redefine target angle. }
- ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
- THEN Ang := Ang+Arc { If foe found, redefine target angle. }
- ELSE Arc := 10;
- { Foe not found in either piece, expand search area to maximum arc. }
- END; {Aim}
-
-
- PROCEDURE BlastThem;
- BEGIN
- Angle := 10;
- REPEAT
- Delta := 10; { Start with widest scanning arc. }
- Range := scan(Angle, Delta);
- WHILE (Range > 40) AND (ObjectScanned = Enemy)
- AND (Range < MaxMissileRange) DO
- { Must be far enough away to avoid self-damage. }
- BEGIN
- Aim(Angle, Delta); { Improve aim. }
- Cannon(Angle, Range); { Fire!! }
- Range := scan(Angle, Delta); { Is foe still in sights? }
- END;
- Angle := Angle+20; { Look in adjacent target area. }
- UNTIL Angle > 360;
- END;
-
-
- PROCEDURE GOTO(x, y : Integer);
- { Go to location X,Y on playing field. }
- VAR Heading : Integer;
- BEGIN
- { Find the heading we need to get to the desired spot. }
- Heading := Angle_To(x, y);
-
- { Keep traveling at top speed until we are within 150 meters }
- WHILE (distance(loc_x, loc_y, x, y) > 150) DO
- BEGIN
- Drive(Heading, MaxSpeed);
- BlastThem;
- END;
-
- { Cut speed, and creep the rest of the way. }
- WHILE (distance(loc_x, loc_y, x, y) > 20) DO
- BEGIN
- Drive(Heading, 20);
- BlastThem;
- END;
-
- { Stop driving, should coast to a stop. }
- Drive(Heading, 0); {I.E., Stop}
- END; {GoTo(X,Y)}
-
-
- PROCEDURE Move;
- { Move to a random spot on the playing field. }
- VAR x, y : Integer;
- BEGIN
- Sweep := 0; { Reset Sweep counter to zero. }
- x := Random(900)+50;
- y := Random(900)+50;
- GOTO(x, y);
- END; {Move}
-
-
- PROCEDURE End_Game;
-
- BEGIN {End_Game}
- GoTo(0,0); {Lower Left Corner}
- Angle := 10; {Sweep arc from 0 to 90 degrees only}
- REPEAT
- Delta := 10; { Start with widest scanning arc. }
- Range := scan(Angle, Delta);
- WHILE (Range > 40) AND (Range < 700) DO
- { Must be far enough away to avoid self-damage. }
- BEGIN
- Aim(Angle, Delta); { Improve aim. }
- cannon(Angle, Range); { Fire!! }
- Range := scan(Angle, Delta); { Is foe still in sights? }
- END;
- Angle := Angle+20; { Look in adjacent target area. }
- IF Angle > 90 THEN Angle := 10;
- UNTIL Dead OR Winner;
- END; {End_Game}
-
-
- BEGIN {HotShot2 Main}
- RaiseShield;
- Angle := 0;
- GoTo(500, 500); { Move to center of field. }
- Sweep := 0; { Initialize Sweep counter to zero. }
- REPEAT { Until Dead or Winner }
- Delta := 10; { Start with widest scanning arc. }
- Range := scan(Angle, Delta);
- WHILE (Range > 40) AND (Range < 700) DO
- { Must be far enough away to avoid self-damage. }
- BEGIN
- Sweep := 0; { Found foe, so reset Sweep to zero }
- Aim(Angle, Delta); { Improve aim. }
- cannon(Angle, Range); { Fire!! }
- Range := scan(Angle, Delta); { Is foe still in sights? }
- END;
- Angle := Angle+20; { Look in adjacent target area. }
- Sweep := Sweep+1;
- IF Sweep >= 18 THEN
- BEGIN { If robot has scanned a full circle, move elsewhere. }
- LowerShield; {Don't need shield (as much) when moving}
- Move;
- END;
-
- RaiseShield; {Standing still so use shield}
-
- {"End" game strategy}
- IF (Fuel < 200) OR (Damage > 70) THEN End_Game;
-
- UNTIL Dead OR Winner;
-
- END; {HotShot2 Main}
-
-
-